<script>
import pushUser from './util/pushUser.js';
// import './static/iconfont/iconfont.css';
// import './static/iconfont/iconfont.js';
// import "@/uni_modules/uview-ui/index.scss";
import { KeepLive } from '@/uni_modules/android-keeplive';
import { getLocationAndroid } from '@/util/getGPS2.js';
let keep = new KeepLive();
export default {
	data() {
		return {
			num: null,
			pushTime: null
		};
	},
	onLaunch: function () {
		console.log('App Launch');
		keep.setTitle('山东千河'); //弹窗title
		keep.setContent('山东千河运行中'); //弹窗内容
		keep.setLargeIcon('icon');
		keep.setSmallIcon('icon'); //图标名字  图标放在 插件下面的 res/drawable 文件夹下
		keep.setWorkerEnabled(true);
		keep.onAddBackgroundCallback(function (res) {
			console.log('后台运行 ' + res);
		});
		//1:保持CPU 运转，屏幕和键盘灯有可能是关闭的,
		keep.setWakeLock(1, 'tag');
		keep.hideNotification(true); //是否隐藏通知栏
	},
	mounted() {},
	onShow: function () {
		console.log('App Show--------------------');
		//取消循环定时
		keep.cancleAleraTask();
		this.pushFn();
		if (this.pushTime) {
			clearInterval(this.pushTime);
			this.pushTime = null;
		}
		//启动监听推送消息事件
		// uni.onPushMessage((res) => {
		// 	console.log('监听推送消息,', res);
		// 	this.$store.commit('setPushBoxText', res.data.content);
		// });
		// this.pushUser();
		pushUser();
		// #ifdef APP-PLUS
		plus.push.clear();
		// #endif
		getLocationAndroid();
	},
	onHide: function () {
		console.log('App Hide=======================');
		this.KeepLiveFn();
		if (this.pushTime) {
			clearInterval(this.pushTime);
			this.pushTime = null;
			// return;
		}
		// this.pushFn();
		// this.pushTime = setInterval(() => {
		// 	// console.log('定时器一分钟');
		// 	// this.pushFn();
		// 	uni.createPushMessage({
		// 		title: '待审核',
		// 		content: `vol.uniapp` + this.base.getDateTime(),
		// 		when: true,
		// 		// cover: true,
		// 		success() {
		// 			console.log('vol.uniapp首页的通知栏执行成功');
		// 		},
		// 		fail() {
		// 			console.log('vol.uniapp首页的通知栏执行失败');
		// 		}
		// 	});
		// 	// }, 1800000);
		// }, 60000); //一分钟
		return;
	},
	methods: {
		KeepLiveFn() {
			keep.onAddScrrenListenerCallback(function (res) {
				console.log('屏幕开启状态 ' + res);
			});
			// keep.requestIgnoreBatteryOptimizations()//开启应用省电后台运行 (闪）
			keep.register(); //注册开启运行
			// if (!keep.isIgnoringBatteryOptimizations()) keep.requestIgnoreBatteryOptimizations();
			keep.startAleraTask(0, 80 * 1000, () => {
				//开启应用省电后台运行
				// if (!keep.isIgnoringBatteryOptimizations()) fkeep.requestIgnoreBatteryOptimizations();
				console.log('onAleraTaskListener ');
				keep.acquire(-1); //唤醒cpu 需先设置唤醒cpu 类型
				const _this = this;
				try {
					_this.http.post('api/Sys_WorkflowtableChange/workflowpushnotifications', {}).then((res) => {
						// console.log('测试接口this.num', _this.num);
						// console.log('测试接口res', res);
						if (_this.num != res.zt && res.hs > 0) {
							_this.num = res.zt;
							uni.createPushMessage({
								title: '待审核',
								content: `您有 ` + res.hs + ' 条数据待审核' + '   ' + _this.base.getDateTime(),
								when: true,
								cover: true,
								success() {
									console.log('首页的通知栏执行成功');
								},
								fail() {
									console.log('首页的通知栏执行失败');
								}
							});
						}
					});
				} catch (e) {
					console.log('error', e);
				}
				keep.releaseAcquire(); // 释放cpu
				// }
			});
		},
		pushFn() {
			try {
				this.http.post('api/Sys_WorkflowtableChange/workflowpushnotifications', {}).then((res) => {
					// console.log('测试接口this.num', this.num);
					// console.log('测试接口res', res);
					if (this.num != res.zt && res.hs > 0) {
						this.num = res.zt;
						uni.createPushMessage({
							title: '待审核',
							content: `您有 ` + res.hs + ' 条数据待审核' + '   ' + this.base.getDateTime(),
							when: true,
							// cover: true,
							success() {
								console.log('首页的通知栏执行成功');
							},
							fail() {
								console.log('首页的通知栏执行失败');
							}
						});
						// ----------------
						// let content = '您有一条新的消息~';
						// let options = {
						// 	cover: false,
						// 	when: new Date(),
						// 	title: '通知消息'
						// };
						// let body = {
						// 	id: 'id',
						// 	key: 'key'
						// };
						// let payload = JSON.stringify(body);
						// plus.push.createMessage(content, payload, options);
						// --------------end
					}
				});
			} catch (e) {
				console.log('error', e);
			}
		}
	}
};
</script>

<style>
@import '@/static/iconfont/iconfont.css';

/*每个页面公共css */
.u-tabbar > .u-tabbar__content {
	padding-bottom: 10rpx;
	border-top: 1px solid #eee;
}

/* 	.u-popup .u-fade-enter-active{
		    z-index: 999999 !important;
	} */
uni-toast {
	z-index: 99999999 !important;
}

uni-page-body,
html,
body {
	height: 100%;
}

uni-page-body > uni-view:first-child {
	height: 100%;
}

.sort-form-popup .u-fade-enter-to {
	z-index: 9999999 !important;
}

.u-button {
	border-color: unset !important;
	border-width: 0 !important;
}

/* 	.grid-u-model>.u-transition {
		z-index: 99999999 !important;
	} */
.grid-u-model .u-transition {
	z-index: 99999999 !important;
}

// #ifdef MP-WEIXIN
page {
	height: 100%;
}

page > view:first-child {
	height: 100%;
}

// #endif

.vol-action-sheet-select-container {
	min-height: 200rpx;
	display: flex;
	flex-direction: column;
}

.vol-action-sheet-select-container .vol-action-sheet-select-title {
	padding: 24rpx;
	text-align: center;
	position: relative;
	border-bottom: 1px solid rgb(233 233 233);
}

.vol-action-sheet-select-container .vol-action-sheet-select-title .vol-action-sheet-select-confirm {
	position: absolute;
	right: 30rpx;
	color: #007aff;
	font-weight: 500;
}

.vol-action-sheet-select-container .vol-action-sheet-select-content {
	flex: 1;
	height: 0;
	overflow: scroll;
}

.u-popup .u-transition {
	z-index: 99999999 !important;
}

.f-form-content-group .u-radio-group {
	justify-content: flex-end !important;
}
</style>